package com.fire.control.system.support.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.springframework.expression.ParseException;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
public class TimeUtil {

	// 根据格式化规则,返回所需要的时间
	public String formatTime(String reg, Date d) {
		SimpleDateFormat sdf = new SimpleDateFormat(reg);
		String newDate = sdf.format(d);
		return newDate;
	}

	/**
	 * 使用参数Format将字符串转为Date
	 * 
	 * @throws java.text.ParseException
	 */
	public static Date parse(String strDate, String pattern) throws ParseException, java.text.ParseException {
		return StringUtils.isEmpty(strDate) ? null : new SimpleDateFormat(pattern).parse(strDate);
	}

	//格式化时间
	public String formatTimeUK(String dateStr, String pattren) throws java.text.ParseException {
		String sDate = "";
		SimpleDateFormat sdf1 = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.UK);
		try {
			Date date = sdf1.parse(dateStr);
			SimpleDateFormat sdf = new SimpleDateFormat(pattren);
			sDate = sdf.format(date);
			System.out.println("Time--------------->"+sDate);
			return sDate;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return sDate;
	}
}
